Ext.define('Zm.controller.NavTree', {
    extend: 'Ext.app.Controller',
    requires:['Zm.Common','Zm.i18n.Lang'],
	stores:['NavTree'],
	refs:[
		{ref:'Nav', selector:'navtree'},
        {ref:'X3dProp', selector:'x3dproperty'},
        {ref:'LineProp', selector:'lineproperty'},
        {ref:'PointProp', selector:'linepointset'},
		{ref:'CardView', selector:'cardview'},
        {ref:'X3dView', selector:'x3dview'}
	],
    
    init: function(){
        var me = this;
        me.control({
			'navtree':{
				itemclick:me.onNavTree
			}
        });
    },
	onNavTree:function(view,record){
		var me = this,view,
			id = record.get('id'),
            prop = me.getX3dProp(),
            lprop = me.getLineProp(),
            pprop = me.getPointProp(),
            x3dview = me.getX3dView();
		view = Ext.ComponentQuery.query(id);
        if(id=='x3dcontainer'){
            x3dview.showLines(false);
            lprop.hide();
            pprop.hide();
            prop.taskRef.start();
        }else if(id=='line'){
            prop.taskRef.start();
        }else if(id=='tour'){
            prop.taskRef.start();
        }else{
            prop.taskRef.stop();
        }
        if(id=='line'){
            view = Ext.ComponentQuery.query('x3dcontainer');
            x3dview.showLines(true);
            x3dview.refLines();
            lprop.show();
            pprop.show();
        }
		if(view.length>0){
			me.getCardView().getLayout().setActiveItem(view[0]);
		}else{
			if(id=='logout'){
                window.location = g_app + '/Index/logout';
            }
		}

        me.application.fireEvent('pagechange',id);
	}
});